# -*- coding: utf-8 -*-
from fly2018.toolkit import jwt_kit


class TenantHolder(object):

    def __init__(self):
        self.tenant_id = 0
        self.user_id = 0
        self.username = ""
        self.tenant_name = ""
        self.is_admin = False;

    def set_by_cookie(self, dt_token):
        pass

    def set(self, request):
        dt_token = request.COOKIES.get("admin_token")
        if dt_token:
            token_json = jwt_kit.decode_token(dt_token)
            self.tenant_id = token_json["tenant_id"]
            if self.tenant_id == 1 or self.tenant_id == '1':
                self.is_admin = True
            self.user_id = token_json["user_id"]
            self.username = token_json["username"]
            self.tenant_name = ''
